/**
  * 角色权限处理
  
  */
import Vue from 'vue'
 import store from '../../store/'
 import {
   Message
 } from 'element-ui'
 export default {
   inserted(el, binding, vnode) {
     const {
       value
     } = binding
     const super_admin = "admin";
     const roles = store.getters && store.getters.roles

     if (value && value instanceof Array && value.length > 0) {
       const roleFlag = value

       const hasRole = roles.some(role => {
         return super_admin === role || roleFlag.includes(role)
       })

       if (!hasRole) {
         el.parentNode && el.parentNode.removeChild(el);
         Message({
           message: "对不起，您无权访问！",
           type: 'error',
           duration:2000
         })

       }
     } else {
       throw new Error(`请设置角色权限标签值"`)
     }
   }
 }
